var mysql = require('mysql');
var conn = mysql.createConnection({
	host: 'localhost',
	port: 3306,
	user: 'root',
	password: 'root',
	database: 'test',
	multipleStatements: true
});


conn.connect();
conn.query('set autocommit=0') //;start transaction;');set autocommit=0

function query(sql, fn) {
	// conn.connect();
	conn.query('set autocommit=0;start transaction;', function(err) {

		conn.query(sql, function(err, data) {
			if (err) {
				conn.query('rollback');
			} else {
				conn.query('commit');
			}
			// conn.end();
			fn(err, data)
		})
	})
}

var d = 'delete from user';
var sql = 'insert into user (name,age,intro) values';
var s1 = '("aaa",11,"aaaIntro")';
var s2 = '("bbb",22,"bbbIntro")';
var s3 = '("ccc",33),"cccIntro")';
var s = 'select * from user';


query(d, function(err, data) {
	query(sql + s1, function(err, data) {
		query(sql + s2, function(err, data) {
			query(sql + s3, function(err, data) {
				query(s, function(err, data) {
					console.log(data);
					conn.end();
				})

			})
		})
	})
})